package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.FileReissue;
import com.amsp.oa.oademo.service.FileReissueService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/file-reissue")
@Api(tags = "文件补发申请单管理")
public class FileReissueController {

    @Autowired
    private FileReissueService fileReissueService;

    @GetMapping("/page")
    @ApiOperation("分页查询文件补发申请单")
    public IPage<FileReissue> getPage(
            @ApiParam("页码") @RequestParam(defaultValue = "1") Integer current,
            @ApiParam("每页大小") @RequestParam(defaultValue = "10") Integer size,
            @ApiParam("关键字") @RequestParam(required = false) String keyword) {
        return fileReissueService.getPage(current, size, keyword);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID获取文件补发申请单")
    public FileReissue getById(@ApiParam("ID") @PathVariable Long id) {
        return fileReissueService.getByIdWithDetails(id);
    }

    @PostMapping
    @ApiOperation("保存或更新文件补发申请单")
    public FileReissue saveOrUpdate(@ApiParam("文件补发申请单") @RequestBody FileReissue fileReissue) {
        return fileReissueService.saveOrUpdateWithDetails(fileReissue);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除文件补发申请单")
    public void delete(@ApiParam("ID") @PathVariable Long id) {
        fileReissueService.removeWithDetails(id);
    }
}